/**
 * @param {number} n
 * @param {number} k
 * @return {number[][]}
 * https://leetcode-cn.com/problems/combinations/
 */
 var combine = function(n, k) {
    let results = [] // 用来存放符合条件的结果的集合
    let path = [] // 用来存放符合条件的结果
    for(let i=1; i<=n; i++){
        path.push(i)
        //此处递归
        backtracking(n, k, i + 1)
        path.pop()
    }


    function backtracking(n, k , start){
        if(path.length === k ){
            results.push([...path])
            return 
        }
    
        for(let j = start; j <= n; j++){
            path.push(j)
            backtracking(n, k, j + 1)
            path.pop()
        }
    }

    console.log(results)
};



let n = 8, k = 4
combine(8, 4)